package Game.Objects;

import java.lang.reflect.InvocationTargetException;

import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import Screens.MyScreens.*;
import Tools.SoundManager;

import GUI.GuiManager;
import GUI.GuiMessenger;
import Game.Items.Others.GIDoorKey;
import Game.Objects.Creatures.GOCreature;

/** Door Key Object class
 * @author Aikidos
 */
public class GODoorKey extends GameObject {

	/** Key id */
	private int _id;
	
	public GODoorKey(ObjectManager objectManager) throws SlickException {
		super(objectManager, "Door Key");
	
		setSprite(new Image("res/gfx/objects/door_key.png"));
		
		_isCanBeUsed = true;
	}
	
	/** Returns id 
	 * @return Id
	 */
	public int getId() {
		return _id;
	}
	
	/** Set id
	 * @param id - New id
	 */
	public void setId(int id) {
		_id = id;
		_name = "Door Key #" + id;
	}

	@Override
	public void use(GameObject user) throws SlickException,
			InstantiationException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException,
			NoSuchMethodException, SecurityException, ClassNotFoundException {
		
		// Player
		if (user.isPlayer()) {
			GOPlayer player = (GOPlayer)user;
			
			// Show message
			GuiManager.getMessenger().addMessage("[green]You[/green] picked a [yellow]" + getName() + "[/yellow]");
			
			GIDoorKey doorKey = new GIDoorKey();
			doorKey.setId(_id);
			player.getInventory().addItem(doorKey);
			_objectManager.destroyObject(this);
			
			// Play sound
			SoundManager.play("sfx_keys");
		}
		
		// Creature
		if (user.isCreature()) {
			GOCreature creature = (GOCreature)user;
			
			GIDoorKey doorKey = new GIDoorKey();
			doorKey.setId(_id);
			creature.getInventory().addItem(doorKey);
			_objectManager.destroyObject(this);
		}
	}
	
}
